package com.siam.package_rider.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.siam.package_common.entity.BasicResult;
import com.siam.package_rider.entity.TbRider;
import com.siam.package_rider.service.TbRiderService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 提供给其他服务Feign客户端调用的用户模块相关接口
 */
@RestController
public class RiderFeignProvider implements RiderFeignApi {

    @Autowired
    private TbRiderService riderService;

//    public BasicResult countByExample(TbRiderParam param) {
//        return BasicResult.success(riderService.countByExample(example));
//    }

    public BasicResult insertSelective(TbRider record){
        riderService.save(record);
        return BasicResult.success();
    }

//    public BasicResult selectByExample(TbRiderParam param) {
//        return BasicResult.success(riderService.selectByExample(example));
//    }

    public BasicResult selectByPrimaryKey(@RequestParam("id") long id){
        return BasicResult.success(riderService.getById(id));
    }

    public BasicResult updateByPrimaryKeySelective(TbRider record){
        riderService.updateById(record);
        return BasicResult.success();
    }

    public BasicResult selectByMobile(@RequestParam("mobile") String mobile){
        return BasicResult.success(riderService.selectByMobile(mobile));
    }

    @Override
    public BasicResult<TbRider> selectByMemberId(Integer memberId) {
        LambdaQueryWrapper<TbRider> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TbRider::getMemberId, memberId);
        List<TbRider> list = riderService.list();
        return BasicResult.success(CollectionUtils.isNotEmpty(list) ? list.get(0) : null);
    }
}